package com.example.RuanJianKeShe.Service.teacher;

import com.alibaba.fastjson.JSON;
import com.example.RuanJianKeShe.Bean.SC;
import com.example.RuanJianKeShe.Dao.impl.StuCourseDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;

@WebServlet("/updataGrade")
public class updataGrade extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("application/json;charset=utf-8");
        String sno = req.getParameter("sno");
        String cno = req.getParameter("cno");
        String grade = req.getParameter("grade");
        SC sc = new SC();
        sc.setSno(Integer.parseInt(sno));
        sc.setCno(Integer.parseInt(cno));
        sc.setGrade(Integer.parseInt(grade));
        StuCourseDaoImpl stuCourseDao = new StuCourseDaoImpl();
        boolean b = stuCourseDao.setStuCourseGrade(sc);
        if (b==true){
            HashMap<String,Object> map = new HashMap<>();
            map.put("success","success");
            String jsonString = JSON.toJSONString(map);
            resp.getWriter().write(jsonString);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
